﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using BLL;

namespace EstateappraisalApi.Controllers
{
    /// <summary>
    /// 用户管理
    /// </summary>
    public class UserController : ApiController
    {

        UsersBLL bll = new UsersBLL();

        /// <summary>
        /// 获取所有的用户信息
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Users> Get()
        {
            return bll.ShowUsers();
        }

        /// <summary>
        /// 查询对应角色的用户
        /// </summary>
        /// <param name="Roles_id">角色编号</param>
        /// <returns></returns>
        public List<Users> get(int Roles_id)
        {
            var user = bll.ShowUsers(Roles_id);

            return user;
        }

        /// <summary>
        /// 登陆
        /// </summary>
        /// <param Users_Account>账号</param>
        /// <param Users_Pwd>密码</param>
        /// <returns></returns>
        public Users get(string Users_Account, string Users_Pwd)
        {
            var user = bll.ShowUsers(Users_Account, Users_Pwd).FirstOrDefault();

            return user;
        }

        // POST api/roles
        /// <summary>
        /// 添加用户信息
        /// </summary>
        /// <param name="value"></param>
        public int Post([FromBody]Users mod)
        {
            mod.Users_CreatePeople = "1";
            mod.Users_CreateTime = DateTime.Now;
            if (bll.AddUsers(mod))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }

        // PUT api/roles/5
        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        public int Put([FromBody]Users m)
        {
            m.Users_CreatePeople = "1";
            m.Users_CreateTime = DateTime.Now;
            if (bll.UpdUsers(m, m.Users_Id))
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }


        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="id"></param>
        [HttpDelete]
        public int Delete(int id)
        {
            Users m = new Users();
            m.Users_Id = id;
            if (bll.DelUsers(m))
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }






    }
}
